package com.cabrida.livestar.pay;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cabrida.livestar.R;
import com.cabrida.livestar.model.BuyData;

/**
 * 购买L币adapter
 * 
 * @author why
 * 
 */
public class PayGvAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private Context mContext;
	private ArrayList<BuyData> data_list = new ArrayList<BuyData>();

	public PayGvAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
		this.mContext = context;
	}

	public void setData(ArrayList<BuyData> data) {
		data_list = data;
	}

	public ArrayList<BuyData> getData() {
		return data_list;
	}

	@Override
	public int getCount() {
		return data_list.size();
	}

	@Override
	public BuyData getItem(int arg0) {
		return data_list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.adapter_pay_gv_item, null);
			holder.ll_bg = (LinearLayout) convertView.findViewById(R.id.ll_bg);
			holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
			holder.tv_unit = (TextView) convertView.findViewById(R.id.tv_unit);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();

		}

		holder.tv_num.setText(data_list.get(position).getC_value().toString());
		if (data_list.get(position).isSelect()) {
			holder.ll_bg.setBackgroundResource(R.drawable.bg_green);
			holder.tv_num.setTextColor(mContext.getResources().getColor(
					R.color.white));
			holder.tv_unit.setTextColor(mContext.getResources().getColor(
					R.color.white));
		} else {
			holder.ll_bg
					.setBackgroundResource(R.drawable.bg_corner_black_white);
			holder.tv_num.setTextColor(mContext.getResources().getColor(
					R.color.text_666));
			holder.tv_unit.setTextColor(mContext.getResources().getColor(
					R.color.text_666));

		}

		return convertView;
	}

	class ViewHolder {
		private LinearLayout ll_bg;
		private TextView tv_num;
		private TextView tv_unit;
	}

}
